package ma.projet.managedbean;

import java.util.Date;
import java.util.List;

import javax.faces.context.FacesContext;

import org.hibernate.HibernateException;

import ma.projet.beans.Infermiere;
import ma.projet.beans.Medecin;
import ma.projet.beans.Mesure;
import ma.projet.beans.Patient;
import ma.projet.beans.Visite;
import ma.projet.service.MedecinService;
import ma.projet.service.MesureService;
import ma.projet.service.PatientService;
import ma.projet.service.VisiteService;

public class VisiteBean {

	private Patient patient;
	private Visite visite;
	private Mesure mesure;
	private Infermiere infermiere;

	private Medecin medecin;
	private String medecinid;
	private String patientid;
	private List<Medecin> medecins;
	private String description;
	private Date dated;

	public VisiteBean() {
		mesure = new Mesure();
		medecin = new Medecin();
	}

	public Patient getPatient() {
		return patient;
	}

	public void setPatient(Patient patient) {
		this.patient = patient;
	}

	public Medecin getMedecin() {
		return medecin;
	}

	public void setMedecin(Medecin medecin) {
		this.medecin = medecin;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getDated() {
		return dated;
	}

	public void setDated(Date dated) {
		this.dated = dated;
	}

	public List<Medecin> getMedecins() {
		if (medecins == null)
			try {
				medecins = new MedecinService().load();

			} catch (HibernateException e) {
				System.out.println("Erreur Liste");
			}

		return medecins;
	}

	public void setMedecins(List<Medecin> medecins) {
		this.medecins = medecins;
	}

	public String getPatientid() {
		return patientid;
	}

	public void setPatientid(String patientid) {
	
		this.patientid = patientid;
	}

	public String getMedecinid() {

		return medecinid;
	}

	public void setMedecinid(String medecinid) {
		this.medecinid = medecinid;
	}

	public Mesure getMesure() {
		return mesure;
	}

	public void setMesure(Mesure mesure) {
		this.mesure = mesure;
	}

	public Visite getVisite() {
		return visite;
	}

	public void setVisite(Visite visite) {
		this.visite = visite;
	}

	public Infermiere getInfermiere() {
		return infermiere;
	}

	public void setInfermiere(Infermiere infermiere) {
		this.infermiere = infermiere;
	}

	public void add() {
		
		visite = new Visite();

		visite.medecin = new MedecinService().getById(Integer
				.parseInt(medecinid));
		visite.patient = new PatientService().getById(Integer
				.parseInt(patientid));
		visite.setdesc(description);
		visite.setDatedebv(new Date());
		new VisiteService().create(visite);
		mesure.setDatedebm(new Date());
		mesure.visite = visite;
		mesure.infermiere = infermiere;
		new MesureService().create(mesure);
		FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove("VisiteBean");
	}
}
